package com.saclub.app.common;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.offroader.utils.LogUtils;
import com.saclub.app.R;
import com.saclub.app.activity.HomeActivity;
import com.saclub.app.activity.MyToolBarActivity;
import com.saclub.app.fragment.AccountContactUsFragment;
import com.saclub.app.fragment.AccountEditFragment;
import com.saclub.app.fragment.AccountFragment;
import com.saclub.app.fragment.AccountLoginFragment;
import com.saclub.app.fragment.AccountMyFavFragment;
import com.saclub.app.fragment.AccountRegFragment;
import com.saclub.app.fragment.AcountServiceRightFragment;
import com.saclub.app.fragment.CommonListFragment;
import com.saclub.app.fragment.MainFragment;
import com.saclub.app.fragment.SingleWebViewFragment;
import com.saclub.app.fragment.WelcomeFragment;

public enum MyPageHelper {

	main(R.string.app_name, MainFragment.class), //主框架
	webView(R.string.main_single_webview_title, SingleWebViewFragment.class), //
	mainCommonList(R.string.main_common_list_title, CommonListFragment.class), //
	account(R.string.main_tab_account_title, AccountFragment.class), //
	accountLogin(R.string.main_account_login_title, AccountLoginFragment.class), //
	accountReg(R.string.main_account_reg_title, AccountRegFragment.class), //
	accountEdit(R.string.main_account_edit_title, AccountEditFragment.class), //
	accountMyFavorite(R.string.main_account_my_favorite_title, AccountMyFavFragment.class), //
	accountContactUs(R.string.main_account_contact_us_title, AccountContactUsFragment.class), //
	accountServiceRight(R.string.main_account_service_right_title, AcountServiceRightFragment.class), //
	welcome(R.string.welcome_title, WelcomeFragment.class), //
	;

	private int title;
	private Class<?> clz;

	private MyPageHelper(int title, Class<?> clz) {
		this.title = title;
		this.clz = clz;
	}

	public void showMyPage(Activity ctx) {
		Bundle args = new Bundle();
		showMyPage(ctx, args);
	}

	public void showMyPageFullScreen(Activity ctx, Bundle args) {
		Intent intent = new Intent(ctx, HomeActivity.class);
		showMyPage(ctx, args, intent, 0);

	}

	public void showMyPage(Activity ctx, int resultCode) {

		Intent intent = new Intent(ctx, MyToolBarActivity.class);
		Bundle args = new Bundle();

		showMyPage(ctx, args, intent, resultCode);

	}

	public void showMyPage(Activity ctx, Bundle args, int resultCode) {

		Intent intent = new Intent(ctx, MyToolBarActivity.class);

		showMyPage(ctx, args, intent, resultCode);

	}

	public void showMyPage(Activity ctx, Bundle args) {

		Intent intent = new Intent(ctx, MyToolBarActivity.class);

		showMyPage(ctx, args, intent, 0);

	}

	public void showMyPage(Activity ctx, Bundle args, String title) {

		Intent intent = new Intent(ctx, MyToolBarActivity.class);
		args.putString(MyToolBarActivity.BUNDLE_KEY_TITLE, title);

		showMyPage(ctx, args, intent, 0);

	}

	public void showMyPageClearTop(Activity ctx, Bundle args) {

		Intent intent = new Intent(ctx, MyToolBarActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

		showMyPage(ctx, args, intent, 0);

	}

	private void showMyPage(Activity ctx, Bundle args, Intent intent, int resultCode) {

		if (args == null)
			args = new Bundle();

		//标题
		if (!args.containsKey(MyToolBarActivity.BUNDLE_KEY_TITLE))
			args.putString(MyToolBarActivity.BUNDLE_KEY_TITLE, ctx.getString(title));

		intent.putExtra(MyToolBarActivity.BUNDLE_KEY_ARGS, args);
		intent.putExtra(MyToolBarActivity.BUNDLE_KEY_NAME, name());

		if (resultCode != 0) {
			ctx.startActivityForResult(intent, resultCode);
		} else {
			ctx.startActivity(intent);
		}

	}

	public void showMyWebViewPage(Activity ctx, String url, String title) {

		Bundle args = new Bundle();
		showMyWebViewPage(ctx, url, title, args);

	}

	public void showMyWebViewPage(Activity ctx, String url, String title, Bundle args) {
		LogUtils.info("接口请求|打开网页" + title + "|" + url);

		if (args == null)
			args = new Bundle();

		args.putString(SingleWebViewFragment.BROWSER_URL, url);
		args.putString(MyToolBarActivity.BUNDLE_KEY_TITLE, title);
		showMyPage(ctx, args);
	}

	public int getTitle() {
		return title;
	}

	public Class<?> getClz() {
		return clz;
	}

	public static MyPageHelper getPageByName(String name) {

		return MyPageHelper.valueOf(name);
	}
}
